﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using ReflectionStudio.Core.Events;
using System.Threading;
using System.Threading.Tasks;
namespace WPFExcelReport
{
    public partial class CB9314
    {
    
        public CB9314()
        {
            try
            {
                if (DesignerProperties.GetIsInDesignMode(this))
                    return;
                SDSA = "9314";
                InitializeComponent();

            }
            catch(Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            } 
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e); 
            if (dwMaster == null)
            {
                KEY = "";
                V1 = "00"; 
            }
            else
            {
                KEY = dwMaster["KEY"].ToString();
                V1 = dwMaster["V1"].ToString(); 
            }
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded) return;
            base.Window_Loaded(sender, e);
            // LOADALL();
            NormalTask = Task.Factory.StartNew(() => LOADALL(), new CancellationTokenSource().Token, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }
        public override void LOADALL()
        {
            base.LOADALL();
            if (LMS.Length > 0)
            {
                filter = "KEY='" + LMS + "'";
                rows = TBMain.Select(filter);
                if (rows.Length > 0)
                {
                    TBTemp = rows.CopyToDataTable();
                    TBMain.Clear();
                    TBMain.Merge(TBTemp);
                    vwMaster.View.MoveCurrentToFirst(); 
                }
            }
        }
        public override void NewCommand(object sender, RoutedEventArgs e)
        {
            YPINFO = "";
            YPINFO = KEY.PadRight(10)+ dwMaster["SDES"].ToString().Trim().PadRight(10)+ dwMaster["V1"].ToString().Trim().PadRight(10);
         }
    }
}
